<?php include TMPL_PATH . 'public/header.phtml'; ?>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/jscal2.css"/>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/border-radius.css"/>
<link rel="stylesheet" type="text/css" href="/statics/js/calendar/win2k.css"/>
<script type="text/javascript" src="/statics/js/calendar/calendar.js"></script>
<script type="text/javascript" src="/statics/js/calendar/lang/zh-cn.js"></script>
<style type="text/css">
</style>
<title></title>
<?php if (!$_REQUEST['is_ajax']): ?>
    <div class="subnav">
        <form name="searchform" action="<?php echo U('order/order_list', array("is_gift_orders" => 1)); ?>"
              method="post">
            <div class="content-menu ib-a blue line-x">
                <div style="float:left;margin-right:50px;">
                    <a href='javascript:;' onclick="ButtonSelect('all');"
                       class="on"><em <?php if ($buttonselect == 'all') echo 'style="font-size:18px;"'; ?> >全部订单</em></a>
                    <a href='javascript:;' onclick="ButtonSelect('wait');" class="on"
                       title="支付时间未满24小时的订单"><em <?php if ($buttonselect == 'wait') echo 'style="font-size:18px;"'; ?> >等待的订单</em></a>
                    <a href='javascript:;' onclick="ButtonSelect('pause');" class="on"
                       title="所有暂停的订单,需要跟进"><em <?php if ($buttonselect == 'pause') echo 'style="font-size:18px;"'; ?> >暂停的订单[
                            <font style="color:#E10000; font-weight:bold;"><?php echo $order_pause; ?></font> ]</em></a>
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    每页显示<input type="text" class="input-text" value="<?php echo $pageRows; ?>" name="pageRows"
                               style="width:30px;">条订单
                </div>
                <div style="color:#000;">
                    <input type="hidden" value="1" name="search">
                    订单状态：<select name="order_status" id="order_status">
                        <option value='9999' <?php if (9999 == $order_status) echo 'selected'; ?>>≡ 全部 ≡</option>
                        <?php foreach (OrderModel::$orderStatusCn as $status_key => $status_name): ?>
                            <option
                                value='<?php echo $status_key ?>' <?php if ($status_key == $order_status) echo 'selected'; ?>><?php echo $status_name; ?></option>
                        <?php endforeach; ?>
                    </select>
                    &nbsp;&nbsp;&nbsp;配送状态：<select name="shipping_status" id="shipping_status">
                        <option value='9999' <?php if (9999 == $shipping_status) echo 'selected'; ?>>≡ 全部 ≡</option>
                        <?php foreach (OrderModel::$giftshippingStatus as $status_key => $status_name): ?>
                            <option
                                value='<?php echo $status_key ?>' <?php if (!is_null($shipping_status) && $status_key == $shipping_status) echo 'selected'; ?>><?php echo $status_name; ?></option>
                        <?php endforeach; ?>
                    </select>
                    &nbsp;&nbsp;&nbsp;<select name="searchtype" id="searchtype">
                        <option <?php if ($searchtype == 0) echo 'selected'; ?> value="0">订单号</option>
                        <option value="3" <?php if ($searchtype == 3) echo 'selected'; ?>>订单id</option>
                        <option value="1" <?php if ($searchtype == 1) echo 'selected'; ?>>收货人</option>
                        <option value="4" <?php if ($searchtype == 4) echo 'selected'; ?>>会员账号(email)</option>
                        <option value="5" <?php if ($searchtype == 5) echo 'selected'; ?>>手机号码</option>
                    </select>
                    <input type="text" class="input-text" value="<?php echo $searchkeyword; ?>" name="keyword"
                           id="keyword">
                    <tr class="xianshi02">
                        <th width="120">下单时间：</th>
                        <td>
                            <input class="input-text" name="c_start_time" type="text" id="c_start_time" size="22"
                                   value='<?php echo $c_start_time; ?>'/>--
                            <script type="text/javascript">
                                Calendar.setup({
                                    weekNumbers: false,
                                    inputField: "c_start_time",
                                    trigger: "c_start_time",
                                    dateFormat: "%Y-%m-%d",
                                    showTime: false,
                                    minuteStep: 1,
                                    onSelect: function () {
                                        this.hide();
                                    }
                                });
                            </script>
                            <input class="input-text" name="c_end_time" type="text" id="c_end_time" size="22"
                                   value='<?php echo $c_end_time; ?>'/>
                            <script type="text/javascript">
                                Calendar.setup({
                                    weekNumbers: false,
                                    inputField: "c_end_time",
                                    trigger: "c_end_time",
                                    dateFormat: "%Y-%m-%d",
                                    showTime: false,
                                    minuteStep: 1,
                                    onSelect: function () {
                                        this.hide();
                                    }
                                });
                            </script>
                        </td>

                    </tr>
                    <input type="hidden" value="1" class="button" name="is_gift_orders">
                    <input type="button" value="搜索" class="button" name="time_search">
                    </tr>
                </div>
            </div>
    </div>
    </form>
    </div>
    <script type="text/javascript">
        function execlPro() {
            $('#excel').val(1);
            $('form[name="searchform"]').attr('action', '<?php echo U('order/order_list', array("is_gift_orders" => 1));?>');
            $('form[name="searchform"]').submit();
            $('#excel').val(0);
        }
        $('input[name="order_measure"]').bind('click', function () {
            $('#list_measure_excel').val(1);
            execlPro();
            $('#list_measure_excel').val(0);
        })
        $('input[name="order_count"]').bind('click', function () {
            $('#order_count_excel').val(1);
            execlPro();
            $('#order_count_excel').val(0);
        })
        $('input[name="order_list_export"]').bind('click', function () {
            $('form[name="searchform"]').attr('action', '<?php echo U('order/order_list_export');?>');
            $('form[name="searchform"]').submit();
        })
        $('input[name="time_search"]').bind('click', function () {
            $('form[name="searchform"]').attr('action', '<?php echo U('order/order_list', array("is_gift_orders" => 1));?>');
            $('form[name="searchform"]').submit();
        })
    </script>
<?php endif; ?>
<div class="bk"></div>
<div class="pad_10">
    <div class="table-list">
        <form action="<?php echo U('order/beach_select_edit'); ?>" method="post" name="myform" id="myform"
              target="_blank">
            <table width="100%" cellspacing="0">
                <thead>
                <tr>
                    <th width="30" align="center"><input type="checkbox" onclick="selectall('oids[]');" id="check_box"
                                                         value=""></th>
                    <th width="">订单号</th>
                    <th align='left' width="15%">收货人</th>
                    <th align='center' width="15%">订单状态</th>
                    <th align='center' width="5%">下单时间</th>
                    <th align='center' width="5%">更新时间</th>
                    <th align='center' width="5%">来源</th>
                    <?php if ($admin_info['roleid'] == 1) { ?>
                        <th align='center' width="15%">备注</th>
                    <?php } ?>
                    <th width="21%">管理操作</th>
                </tr>
                </thead>
                <tbody>
                <?php
                if (isset($orderList) && $orderList):
                    foreach ($orderList as $k => $v):
                        ?>
                        <tr>
                            <td align="center"><input type="checkbox" name="oids[]" class="oids"
                                                      value="<?php echo $v['id']; ?>"></td>
                            <td align='center'><?php echo $v['id'] ?><br/><?php echo $v['order_sn'] ?></td>
                            <td><?php echo $v['delivery_last_name'] . ($v['delivery_first_name'] ? '.' . $v['delivery_first_name'] : ''); ?><?php echo ' [ ' . ($v['delivery_phone'] ? $v['delivery_phone'] : null) . ' ] '; ?>
                                <br/>
                                <?php echo '[' . $v['delivery_country'] . ($v['delivery_province'] ? ' - ' . $v['delivery_province'] : null) . ' ] ' . $v['delivery_address']; ?>
                            </td>
                            <td align='center'><?php echo OrderModel::$orderStatusCn[$v['order_status']]; ?>,
                                <?php echo OrderModel::$giftshippingStatus[$v['shipping_status']]; ?><?php if ($v['is_cheat'] == 2) {
                                    echo ',<font color="red">疑似欺诈订单</font>';
                                } ?>
                                <?php
                                if ($v['shipping_status'] == OrderModel::SHIPPING_UNSHIPPED) {
                                    $orderlogs = OrderModel::getOrdersLogList($v['id']);
                                    if ($orderlogs) {
                                        foreach ($orderlogs as $kkk => $vvv) {
                                            if ($vvv['shipping_status'] == 99) {
                                                echo ',配货中';
                                                break;
                                            }
                                        }
                                    }
                                }
                                ?>
                            </td>
                            <td align='center'><?php echo date('Y-m-d H:i:s', $v['start_time']); ?></td>
                            <td align='center'><?php if ($v['update_time'] == 0) {
                                    echo '';
                                } else {
                                    echo date('Y-m-d H:i:s', $v['update_time']);
                                } ?></td>
                            <td align='center'><?php echo $v['is_mobile'] == 0 ? "pc" : ($v['is_mobile'] == 1 ? "ipad" : "mobile") ?></td>
                            <?php if ($admin_info['roleid'] == 1) { ?>
                                <td align='center' class="admin_notes_content">
                                    <span class="admin_notes_show"
                                          style="display: inline;word-break:break-all; width:200px;float:left;"><?php echo $v['admin_notes'] ?></span>
                                    <textarea class="admin_notes"
                                              style="display: none;"><?php echo $v['admin_notes'] ?></textarea>
                                    <a href="javascript:;" class="admin_notes_action"
                                       onclick="admin_notes_action($(this),'action');" style="float: right;color: red;">修改备注</a>
                                    <a href="javascript:;" class="admin_notes_confirm"
                                       onclick="admin_notes_action($(this),'confirm');" style="display: none"
                                       order_id="<?php echo $v['id']; ?>">确认</a>&nbsp;
                                    <a href="javascript:;" class="admin_notes_cancel"
                                       onclick="admin_notes_action($(this),'cancel');" style="display: none">取消</a>
                                </td>
                            <?php } ?>
                            <td align='center'>
                                <a href="javascript:openwinx('<?php echo U('order/order_print', 'oid=' . $v['id']) ?>','order_print');">打印清单</a>
                                |
                                <a href="<?php echo U('order/order_edit', 'oid=' . $v['id']); ?>">查看</a> |
					<span <?php if ($_GET['del'] != 1): ?>style="display:none;"<?php endif;
                    ?>>
                    <a href="javascript:confirmdelurl('<?php echo U('order/order_delete', 'oid=' . $v['id']); ?>','确认要删除 『<?php echo $v['order_sn'] ?>』 吗？')">删除</a> |
                    </span>
                                <a href="javascript:void(0);" onclick="cartListShow(this,<?php echo $v['id']; ?>);"
                                   class="as">展开</a> |
                                <?php if ($v['is_size']) { ?> <img src="/admin/Tpl/public/images/check-64.png"
                                                                   width="20px" height="20px" align="absmiddle"
                                                                   title="身型数据设置完成"/> <?php } ?>
                                <?php if ($buttonselect == 'pause'): ?>
                                    <a href="javascript:openwinx('<?php echo U('order/order_log', 'order_id=' . $v['id']); ?>','order_log<?php echo rand(1000, 9999); ?>');">查看原因</a>
                                    <a href="javascript:void(0);" onclick="orderPro(this,<?php echo $v['id']; ?>);"
                                       title="点击恢复，订单恢复到原列表">恢复订单</a>
                                <?php endif; ?>
                                <?php if ($v['remark']) { ?><img src="/admin/Tpl/public/images/pencil_edit.png"
                                                                 width="20px" height="20px" title="此订单有客户留言"
                                                                 align="absmiddle"/> <?php } ?>
                            </td>
                        </tr>
                        <!-- 子信息列表 -->
                        <tr style="display:none;" id="tr_<?php echo $v['id']; ?>" class="ordertrs">
                            <td colspan="11" id="td_<?php echo $v['id']; ?>">

                            </td>
                        </tr>
                        <!-- 子信息列表 -->
                        <?php
                    endforeach;
                else:
                    echo '<tr><td colspan="12" align="center">无订单数据</td></tr>';
                endif;
                ?>
                </tbody>
            </table>
        </form>
        <?php if (!$_REQUEST['is_ajax']): ?>
            <div id="pages"><?php echo $pageShow; ?></div>
        <?php endif; ?>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    //删除订单
    function confirmdelurl(url, tips) {
        if (confirm(tips)) {
            $.ajax({
                type: 'GET',
                url: url,
                success: function (msg) {
                    location.reload();
                }
            });
        }
    }
    function print_pro_note() {
        var oids = '';
        $(".oids").each(function () {
            if ($(this).attr('checked')) {
                oids += ($(this).val() + ',');
            }
        });
        if (oids != '') {
            window.open('<?php echo U('order/print_pro_note', 'ids=');?>' + oids + '&order_print<?php echo rand(1000, 9999);?>');
        }
    }
    function ButtonSelect(val) {
        var hrefstr = "<?php echo U('order/order_list', array("is_gift_orders" => 1));?>"
                /*                     +"&order_status="+$('#order_status').val()
                 +"&payment_status="+$('#payment_status').val()
                 +"&shipping_status="+$('#shipping_status').val()
                 +"&searchtype="+$('#searchtype').val()
                 +"&keyword="+$('#keyword').val()
                 +"&start_time="+$('#start_time').val()
                 +"&end_time="+$('#end_time').val()*/
            + "&buttonselect=" + val;
        location.href = hrefstr;
    }

    function exportAttrExcel(val) {
        var excel_start_time = $("#excel_start_time").val();
        var excel_end_time = $("#excel_end_time").val();
        var model_id = $("#modelid").val();
        if (excel_start_time && excel_end_time) {
            /**
             $.ajax({
			type: 'GET',
			url: "<?php echo U('Order/exportAttrExcel');?>",
			data: {"excel_start_time":excel_start_time,'excel_end_time':excel_end_time},
			dataType:'json',
			success: function(msg) {
				alert(msg.msg);
			}
		});
             */
            var hrefstr = "<?php echo U('order/exportAttrExcel');?>"
                + "&excel_start_time=" + excel_start_time
                + "&excel_end_time=" + excel_end_time
                + "&model_id=" + model_id;
            location.href = hrefstr;
        } else {
            alert("选择时间段");
        }
    }

    function orderTypeUrl() {
        var s = document.getElementById("select").value;

        window.location.href = '<?php echo U('order/order_list', array("is_gift_orders" => 1));?>&yushou_order_type=' + s;
    }

    function locationurl(url) {
        window.location.href = url;
    }

    function cartListShow(obj, id) {
        $('#td_' + id).html('');
        $('.ordertrs').hide();
        ajax_zlist(id);
        $('#tr_' + id).show();
        return;
    }

    function ajax_zlist(id) {
        $.ajax({
            type: 'POST',
            url: "<?php echo U('order/order_zlist');?>&order_id=" + id,
            data: {"round": Math.random(), 'order_id': id},
            dataType: 'html',
            beforeSend: function () {
                $('#td_' + id).html('<div style="text-align:center;font-size:14px;">正在努力加载 ^_^ <br />子订单数据加载中，请稍后...</div>');
            },
            success: function (msg) {
                $('#td_' + id).html(msg);
            }
        });
    }

    function orderPro(obj, id) {
        if (!confirm('确定此订单的暂停原因已处理完毕？')) {
            return false;
        }
        $.ajax({
            type: 'POST',
            url: "<?php echo U('order/order_pro');?>&order_id=" + id,
            data: {
                "round": Math.random(),
                'order_status': '<?php echo OrderModel::ORDER_CONFIRMED;?>',
                'action_notice': '订单从暂停状态恢复'
            },
            success: function (msg) {
                if (msg != '1') {
                    alert(msg)
                }
                {
                    window.location.reload();
                }
            }
        });
    }


    function admin_notes_action(_this, act) {
        if (act == "action") {
            _this.hide();
            _this.siblings(".admin_notes_show").hide();
            _this.siblings(".admin_notes").show();
            _this.siblings(".admin_notes_confirm").show();
            _this.siblings(".admin_notes_cancel").show();
        } else if (act == "cancel") { //取消
            _this.hide();
            _this.siblings(".admin_notes_confirm").hide();
            _this.siblings(".admin_notes").val(_this.siblings(".admin_notes_show").text());
            _this.siblings(".admin_notes").hide();
            _this.siblings(".admin_notes_show").show();
            _this.siblings(".admin_notes_action").show();
        } else if (act == "confirm") { //确认
            _this.hide();
            _this.siblings(".admin_notes_cancel").hide();
            _this.siblings(".admin_notes").hide();
            _this.siblings(".admin_notes_show").show();
            _this.siblings(".admin_notes_action").show();
            var show_admin_notes_text = _this.siblings(".admin_notes_show").text();
            var admin_notes_text = _this.siblings(".admin_notes").val();
            var id = _this.attr("order_id");
            if (show_admin_notes_text == admin_notes_text) {
                alert("备注未做任何修改！");
            } else {
                $.ajax({
                    type: 'POST',
                    url: "<?php echo U('order/edit_order_notes_by_admin');?>&order_id=" + id,
                    data: {'admin_notes': admin_notes_text},
                    success: function (data) {
                        data = JSON.parse(data);
                        if (data.status == 1) {
                            _this.siblings(".admin_notes_show").html(admin_notes_text);
                        } else {
                            _this.siblings(".admin_notes").val(_this.siblings(".admin_notes_show").text());
                            alert(data.msg);
                        }
                    }
                });
            }
        }

    }

</script>
